feat: introduce the Ruff pre-commit hook to replace a bunch of other code formatters and linter hooks#1419
feat: introduce the Ruff pre-commit hook to replace a bunch of other code formatters and linter hooks#1419jenstroeger wants to merge 2 commits into
Conversation
…code formatters and linter hooks Signed-off-by: Jens Troeger <jens.troeger@light-speed.de>
|
@behnazh-w in addition to the existing checks, perhaps it would make sense to add the following:
Also, note that there’s a macaron/.pre-commit-config.yaml Lines 203 to 211 in 109edd2 |
| "Invalid_status_on_skipped", | ||
| [], | ||
| [], | ||
| status_on_skipped, # type: ignore |
There was a problem hiding this comment.
@behnazh-w I am a little confused about this comment. For one, it’s a blanket ignore and it doesn’t specify what error is being ignored here; this line should be
status_on_skipped, # type: ignore[arg-type]But then the question arises: why is this argument type being ignored? Looking at the signature for the initializer
macaron/src/macaron/slsa_analyzer/checks/base_check.py
Lines 24 to 34 in 109edd2
status_on_skipped variable should be macaron/src/macaron/slsa_analyzer/checks/check_result.py
Lines 15 to 26 in 109edd2
status_on_skipped variable is the test function‘s argument macaron/tests/slsa_analyzer/checks/test_registry.py
Lines 156 to 162 in 109edd2
SearchStrategy. But that’s not quite right because @given feeds values from strategies into the test function and not the strategy object. Thus, the function argument receives a list[None | str | int | tuple | bytes | bool] but that still doesn’t match the signature’s CheckResultType. So shouldn’t this test look something like
@given(st.sampled_from(list(CheckResultType)))
def test_exit_on_invalid_status_on_skipped(self, status_on_skipped: CheckResultType) -> None:
...I’ve not tested this.
I then grepped through the code base and there are heaps of blanket type ignores. I think it would therefore make sense to open an issue to review all these blanket ignores, attempt to address them by fixing up the code (see above), and if that’s not possible constrain the ignore to only the error that’s being ignored. By doing so, other type errors will be surfaced if they occur instead of silently swallowing all errors.
Summary
This change replaces
black,bandit,isort,flake8, andpyupgradegit hooks with a singleruffhook.Description of changes
Ruff is supposed to be a drop-in replacement for the aforementioned checkers, linters, and code formatters and it mostly works. However, it also
FooBarExceptionwhich should be namedFooBarErrorwhich could be considered a breaking change;banditcommentsnosec Bxxxtonoqa: Sxxx.In addition to the rules covering the existing Macaron setup, Ruff provides a bunch of new rules and checkers (e.g. boolean trap) that are probably interesting to add… 🤓
Related issues
n/a
Checklist
verifiedlabel should appear next to all of your commits on GitHub.